package service

import (
	"bc/dao"
	"bc/util/library/zstack"
	"encoding/json"
	"fmt"
)

type l2_net struct {

}
func (t *l2_net)Create(d map[string]interface{}) (bool,int){

	b,i :=dao.L2Net.Create(d)
	return b,i

}
func (t *l2_net)Delete(w map[string]interface{}) bool {

	return dao.L2Net.Delete(w)

}
/**
创建VXLAN网络
 */
func (t *l2_net)CreateL2VxlanNetwork(poolUuid string, name string, description string,zoneUuid string, sid int) string{

	l2_map := make(map[string]interface{}, 2)
	params := make(map[string]string, 3)
	params["poolUuid"] = poolUuid
	params["name"] = name
	params["description"] = description
	params["zoneUuid"] = zoneUuid
	l2_map["params"] = params
	l2_map["systemTags"] = []string{}
	l2_map["userTags"] = []string{}
	res_byte,err := json.Marshal(l2_map)
	if err != nil {
		return ""
	}
	result,_ := zstack.NetWork.CreateL2VxlanNetwork(string(res_byte), sid)
	inventory := make(map[string]interface{},10)
	for {
		res := zstack.NetWork.GetResults(result)
		if _,ok := res["error"];ok {

			return ""
		}
		if v,ok := res["inventory"];ok {
			fmt.Println("创建二层网络成功")
			inventory = v.(map[string]interface{})
			break
		}
	}
	return inventory["uuid"].(string)

}
var L2Net = &l2_net{}

